
class K8055
	def initialize(address)
		@deviceAddress = address
		@openDeviceDLL 			= Win32API.new("K8055D.dll","OpenDevice",['I'],'I')		# board address
		@closeDeviceDLL 		= Win32API.new("K8055D.dll","CloseDevice",[],'V')
		@readAnalogChannelDLL           = Win32API.new("K8055D.dll","ReadAnalogChannel",['I'],'I') # channel
		@readAllAnalogDLL		= Win32API.new("K8055D.dll","ReadAllAnalog",['I','I'],'V') # ref data1, data2
		@outputAnalogChannelDLL         = Win32API.new("K8055D.dll","OutputAnalogChannel",['I','I'],'V') # channel,data
		@outputAllAnalogDLL		= Win32API.new("K8055D.dll","OutputAllAnalog",['I','I'],'V') #data, data
		@clearAnalogChannelDLL          = Win32API.new("K8055D.dll","ClearAnalogChannel",['I'],'V') #channel
		@setAllAnalogDLL		= Win32API.new("K8055D.dll","SetAllAnalog",[],'V')
		@clearAllAnalogDLL		= Win32API.new("K8055D.dll","ClearAllAnalog",[],'V')
		@setAnalogChannelDLL		= Win32API.new("K8055D.dll","SetAnalogChannel",['I'],'V')	
		@writeAllDigitalDLL		= Win32API.new("K8055D.dll","WriteAllDigital",['I'],'V')
		@clearAllDigitalDLL		= Win32API.new("K8055D.dll","ClearAllDigital",[],'V')
		@setAllDigitalDLL		= Win32API.new("K8055D.dll","SetAllDigital",[],'V')
		@readDigitalChallenDLL          = Win32API.new("K8055D.dll","ReadDigitalChannel",['I'],'L');
		@readAllDigitalDLL		= Win32API.new("K8055D.dll","ReadAllDigital",[],'I')
		@readCounterDLL			= Win32API.new("K8055D.dll","ReadCounter",['I'],'I')
		@resetCounterDLL		= Win32API.new("K8055D.dll","ResetCounter",['I'],'V')
		@setCounterDebounceTimerDLL     = Win32API.new("K8055D.dll","SetCounterDebounceTime",['I','I'],'V')		#(int CounterNr, int DebounceTime);
		@versionDLL			= Win32API.new("K8055D.dll","Version",[],'V')
		@searchDevicesDLL		= Win32API.new("K8055D.dll","SearchDevices",[],'I')
		@setCurrentDeviceDLL		= Win32API.new("K8055D.dll","SetCurrentDevice",['I'],'I')
		
		
		@clearDigitalChannelDLL = Win32API.new("K8055D.dll","ClearDigitalChannel",['I'],'V')
		@setDigitalChannelDLL = Win32API.new("K8055D.dll","SetDigitalChannel",['I'],'V')
		result = openDevice(@deviceAddress)
	end
	
	def openDevice(channel)
      return @openDeviceDLL.Call(channel)
   end
   
   def clearDigitalChannel(channel)
      @clearDigitalChannelDLL.Call(channel)
   end
   def setDigitalChannel(channel)
      @setDigitalChannelDLL.Call(channel)
   end
   
   # fix these
   def outputAnalogChannel(channel,value)
      @outputAnalogChannelDLL.Call(channel,value)
   end
   
   def testOutputs
      Thread.new {
         while(1)
            n = 0
            while(n<9)
               clearDigitalChannel(n)
               n = n+1
               setDigitalChannel(n)
               sleep 0.1               
            end
         end
      }
   end
end
